<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
        <title>表单列表渲染</title>
        <{$showjs}>
        <link rel="stylesheet" type="text/css" href="../css/main1.css" />
        <script type="text/javascript" src="/Plug-in/ext/Ext.grid.CheckColumn.js"></script>
        <script type="text/javascript" src="/Plug-in/ext/Ext.Store.Sort.js"></script>
        <script type="text/javascript" src="/Plug-in/ext/Ext.form.Property.js"></script>
        <style type="text/css">
            .add{background:url(../img/add.gif) no-repeat 1px 2px !important;}
            .copy{background:url(../img/copy.gif) no-repeat 1px 2px !important;}
            .del{background:url(../img/del.gif) no-repeat 1px 2px !important;}
            .edit{background:url(../img/edit.gif) no-repeat 1px 2px !important;}
            .search{background:url(../img/find.gif) no-repeat 1px 2px !important;}
            .hidea{background:url(../img/arrow_out.png) no-repeat 1px 2px !important;}
            .hideb{background:url(../img/arrow_in.png) no-repeat 1px 2px !important;}
            .fsadd{background:url(../img/icon_extension.gif) no-repeat 1px 2px !important;}
            .fslist{background:url(../img/list_extensions.gif) no-repeat 1px 2px !important;}
            .real_time{background:url(../img/date_edit.png) no-repeat 1px 2px !important;}
            .exportExcel{background:url(../img/page_excel.png) no-repeat 1px 2px !important;}
            .x-plain{color:#fff;}

            .x-check-group-alt {
                background: #D1DDEF;
                border-top:1px dotted #B5B8C8;
                border-bottom:1px dotted #B5B8C8;
            }
        </style>
        <script language="javascript">
            //分页数量
            var perpage = parseInt("<{if $smarty.get.limit == ''}>15<{else}><{$smarty.get.limit}><{/if}>");

            function gxzd(id,zd,xz){			
                Ext.Ajax.request({
                    waitMsg:'数据处理中...',
                    url:'./<{$tisurl}>',
                    method:'POST',
                    params:{
                        op:'gxzd',
                        id:id,
                        tname:'<{$table.tabname}>',
                        zd:zd,
                        xz:xz
                    },
                    success:function(response){
                        var bbb =Ext.query("button[class*='loading']");
                        bbb[0].click();
                    },
                    failure:function(response){
                        Ext.MessageBox.alert('警告',"无法连接数据库!");
                    }
		
                });
            }
            function tjpx(tid,zd){
                var pr=top.Ext.get('px'+tid+zd);
                if(pr){
                    pr.close();
                }
                top.xajax_loadUrl('拖拽排序-'+tid+'_'+zd,'./show1/px.php?&op=show&lg=<{$lg}>&tid='+tid+'&zd='+zd,'416',top.Ext.getBody().getHeight(),false,'px'+tid+zd);
            }

            <!--
            Ext.onReady(function (){

                //信息提示选项   
                Ext.QuickTips.init();
                //将一些配置属性应用到此单态
                Ext.apply(Ext.QuickTips.getQuickTip(), {
                    showDelay: 50,
                    trackMouse: true,
                    dismissDelay: 0
                });
                Ext.form.Field.prototype.msgTarget = 'side';//设置提示信息位置为边上
                //信息提示选项end
                var myMask = new Ext.LoadMask(Ext.getBody(), {
                    msg: '请稍候...',
                    removeMask: true
                });
                //grid 复选栏控件
                var checkColumn = new Ext.grid.CheckColumn({
                    header: "Indoor",
                    dataIndex: 'indoor',
                    width: 55
                });
                //grid 复选栏控件end

                //ds 参数
                var data = {url : "./index.php" , method:'POST'};//异步参数
                var requestParams = {op : 'fy',tid:<{$tid}> ,bdtid:'<{$bdtid}>' , bdid :'<{$bdid}>',dbname:'<{$table.tabname}>',lg:'<{$lg}>'}; //请求参数,store 每次请求都发送的参数,可在这里设定,id gid sortid 等信息
                var sm = new Ext.grid.CheckboxSelectionModel();
                //cm 参数
                var cmCfg = [
                    //					checkColumn,
                    sm,//原样写就可以
                    {header:'ID',dataIndex:'id',width:50,sortable:true,readOnly:true,renderer: function(v,p){p.attr+= "ext:qtip='"+ v + "'";return v;}},
                        <{section name=li loop=$xr}>
                        {id:'<{$xr[li].id}>',tooltip:'<{$xr[li].name}>',header:'<{$xr[li].name}>',dataIndex:'<{$xr[li].fname}>',width:<{$xr[li].wd}>,sortable:true<{if $xr[li].renderer neq ''}><{$config[li].renderer}><{else}><{if $xr[li].type != 'recommend' && $xr[li].type != 'fileup'}>,renderer: function(v,p){p.attr+= "ext:qtip='"+ v + "'";return v;}<{/if}><{/if}>}
                        <{if $smarty.section.li.index+1 < $xr|@count}>,<{/if}>
                        <{/section}>
                    ];


                //ds解析模型 用于ds 的reader
                var robj = [		
                    //	{name: 'indoor', type: 'bool'},
                    new Ext.grid.RowNumberer(),//原样写就可以
                    {name: 'id',type:'int'},
                        <{section name=li loop=$xr}>
                        {name:'<{$xr[li].fname}>'}
                        <{if $smarty.section.li.index+1 < $xr|@count}>,<{/if}>
                        <{/section}>
                    ];

                // ds reader
                var rd = new Ext.data.JsonReader({
                    totalProperty:'total',
                    root:'data',
                    id:'jsonreader'
                },robj);



                var ds = new Ext.data.Store({
                    proxy: new Ext.data.HttpProxy(data),
                    reader:rd,
                    baseParams:requestParams,
                    sortInfo:{field :'<{$paixu.zd}>',direction:'<{$paixu.order}>'}
                });


                var cm = new Ext.grid.ColumnModel(cmCfg);


                var advSearchForm=new Ext.FormPanel({
                    id:'advSearchForm',
                    name:'advSearchForm',
                    labelWidth:55,
                    border:false,
                    autoScroll:true,
                    autoHight:true,
                    labelAlign:'right',
                    bodyStyle:'padding:5px',
                    buttunAlign:'left',
                    layout:'form',
                    plain:true,
                    frame:true,
                    items:[
                        {
                            xtype:'hidden',
                            name: 'tid',
                            value:'<{$tid}>'
                        },{
                            xtype:'hidden',
                            name: 'lg',
                            value:'<{$lg}>'
                        },{
                            xtype:'hidden',
                            name: 'bdtid',
                            value:'<{$bdtid}>'
                        },{
                            xtype:'hidden',
                            name: 'bdid',
                            value:'<{$bdid}>'
                        }
                            <{section name=li loop=$js}>
                            ,<{$js[li]}>
                            <{/section}>
                        ],
                    buttons:[
                        {text:'搜索',iconCls:'search',handler:function (){
				
                                /*					for (elm in advSearchForm.getForm().getValues(false)) {
                                                        alert(elm); 
                                                        }   
                                 */
                                var searchobj=advSearchForm.getForm().getValues(false);
                                //			alert(advSearchForm.getForm().getValues(true));
                                searchobj.start=0;
                                searchobj.limit=perpage;
                                //alert(searchobj);
                                ds.load({
                                    params:searchobj
                                });
                                advSearchwin.hide();
                            }},
                        {text:'取消',handler:function (){
                                advSearchForm.form.reset();
                                //			    advSearchwin.hide();
                            }}
                    ]
                });
                var advSearchwin=new Ext.Window({
                    title:'高级搜索',
                    id:'advSearchwin',
                    collapsible : true,
                    /*			tools : [ 
                                        {id:'toggle'}, 
                                        {id:'close'}, 
                                        {id:'maximize'} 
                                   ], */
                    width:700,
                    autoHight:true,
                    closeAction:'hide',
                    plain:true,
                    items:advSearchForm
                });



                var adstatus=0;
                function searchHandeler(){
                    advSearchwin.show();
                    adstatus=1
                }

                function delHandeler(){
                    if(grid.selModel.getCount()==1){
                        Ext.MessageBox.confirm("操作确认","你确认删除当前选择项目?",delTask);
                    }else if(grid.selModel.getCount()>1){
                        Ext.MessageBox.confirm("警告","你确认删除选中的项目?",delTask);
                    }else{
                        Ext.MessageBox.alert('消息',"你没有选中项目");
                    }  
                }
                function editHandeler(){
                    if(grid.selModel.getCount()==1){
                        var selections = grid.selModel.getSelections();
                        var pr=top.Ext.get('adddata<{$tree.id}>');
                        if(pr){
                            pr.close();
                        }
                        top.xajax_loadUrl('编辑<{$tree.title}>[<{$tree.id}>]_<{$table.name}>[<{$table.tabname}>]数据','./dy/index.php?op=loaddata&tid=<{$tree.id}>&id='+selections[0].json.id+'&lg=<{$lg}>',top.Ext.getBody().getWidth(),top.Ext.getBody().getHeight(),false,'adddata<{$tree.id}>');
                    }else if(grid.selModel.getCount()>1){
                        Ext.MessageBox.alert("提示","本操作无法批量完成");
                    }else{
                        Ext.Msg.alert("提示消息","请选择一行数据然后才能够编!");return false;
                    }
                }
                function addHandeler(){
                    var pr=top.Ext.get('adddata<{$tree.id}>');
                    if(pr){
                        pr.close();
                    }
                    top.xajax_loadUrl('向<{$tree.title}>[<{$tree.id}>]_<{$table.name}>[<{$table.tabname}>]添加数据','./dy/index.php?op=loaddata&tid=<{$tree.id}>&bdtid=<{$bdtid}>&bdid=<{$bdid}>&lg=<{$lg}>',top.Ext.getBody().getWidth(),top.Ext.getBody().getHeight(),false,'adddata<{$tree.id}>');
                }
                function fsadd(fstid,title,url,id){
                    var pr=top.Ext.get('adddata'+fstid);
                    if(pr){
                        pr.close();
                    }
                    top.xajax_loadUrl('添加绑定数据-'+title,url+id,top.Ext.getBody().getWidth(),top.Ext.getBody().getHeight(),false,'adddata'+fstid);
                }
                function fslist(fstid,title,url,id){
                    var pr=top.Ext.get('list'+fstid);
                    if(pr){
                        pr.close();
                    }
                    top.xajax_loadUrl('浏览绑定数据-'+title,url+id,top.Ext.getBody().getWidth(),top.Ext.getBody().getHeight(),false,'list'+fstid);
                }

                //删除处理
                function delTask(btn){
                    if (btn=='yes'){
                        var selections = grid.selModel.getSelections();
                        var prez = [];
                        for(i = 0; i< grid.selModel.getCount(); i++){
                            prez.push(selections[i].json.id);
                        }

                        var encoded_array= Ext.encode(prez);

                        Ext.Ajax.request({
                            waitMsg:'正在操作',
                            url:'./<{$thisurl}>',
                            method:'POST',
                            params:{
                                op:'del',
                                tid:'<{$tree.id}>',
                                ids:encoded_array,
                                dbname:'<{$table.tabname}>'
                            },
                            success:function(response){
                                Ext.MessageBox.alert('消息',"数据删除成功！");
                                ds.reload();
                                grid.refresh();
                            },
                            failure:function(response){
                                Ext.MessageBox.alert('警告',"无法连接数据库!");
                            }

                        });

                    }
                }
                //删除end
                //edit
                var oneTbar=new Ext.Toolbar({   
                    items:[   
                        {text:'当前页C值总量：<font color=red>0</font>元',id:'dq'},   
                        {text:'系统注入C值资源滚动总量：<font color=red>0</font>元',id:'zong'}
                    ]     
                });   

                //标题搜索
                var sbar=new Ext.FormPanel({
                    baseCls: 'x-plain',
                    bodyStyle:'padding:5px 0 0 0',
                    defaults: {width:150},
                    labelWidth:80,
                    defaultType: 'textfield',
                    items: [{
                            fieldLabel: '<{$thistitle}>检索',
                            id:'<{$titlesearch}>',
                            name: '<{$titlesearch}>'
                        }]
                });
                var searObj= {
                    text: '搜索',
                    handler:function(){
                        ds.load({
                            params:{
                                    <{$titlesearch}>:Ext.get('<{$titlesearch}>').dom.value,start:0,limit:perpage
                            }
                        })
                    }
                };
                //标题搜索end


                var grid = new Ext.grid.GridPanel({
                    el:'cms-grid-el',
                    id:'cms-grid-id',
                    //		plugins:checkColumn,
                    clicksToEdit:1,
                    ds:ds,
                    cm:cm,
                    sm:sm,//selModel:new Ext.grid.RowSelectionModel({singleSelect:false}),
                    tbar: [
                        sbar,
                        searObj,
                        new Ext.Toolbar.Separator(),
                        {text:'高级d搜索',iconCls:'search',tooltip:'高级搜索',handler:searchHandeler},
                            <{if ($rightid|getright:"u")}>
                            new Ext.Toolbar.Separator(),
                        {text:'编辑',iconCls:'edit',handler:editHandeler},<{/if}>
                            <{if ($rightid|getright:"c")}>
                            new Ext.Toolbar.Separator(),
                        {text:'添加',iconCls:'add',handler:addHandeler},<{/if}>
                            <{if ($rightid|getright:"d")}>new Ext.Toolbar.Separator(),
                        {text:'删除',iconCls:'del',handler:delHandeler},<{/if}>
                            new Ext.Toolbar.Separator(),
                        {text:'<font color=yellow><b>隐藏周边</b></font>',iconCls:'hidea',handler:function (){
                                if(!window.top.west.collapse(true)){
                                    window.top.west.expand(false);
                                    this.setIconClass('hidea');
                                    this.setText("<font color=yellow><b>隐藏周边</b></font>");
                                    this.blur;
                                }else{
                                    this.setIconClass('hideb');
                                    this.setText("<font color=red><b>显示周边</b></font>");
                                    this.blur;
                                }
                                if(!window.top.north.collapse(true)){
                                    window.top.north.expand(false);
                                }

                            }},
                        new Ext.Toolbar.Separator(),
                        {text:'刷新',iconCls:'i_czxt',handler:function (){
                                window.location.reload();
                            }}
                            <{if $tree_config.excelExport == 1}>
                            ,new Ext.Toolbar.Separator()
                        ,{text:'导出',iconCls:'exportExcel',handler:function (){
                                exportExcel('<{$smarty.get.tid}>');
                            }}
                            <{/if}>
                            ,new Ext.Toolbar.Separator()
                        ,new Ext.FormPanel({
                            baseCls: 'x-plain',
                            bodyStyle:'padding:5px 0 0 0',
                            labelWidth:80,
                            width:150,
                            items: [{
                                    xtype:'textfield',
                                    width:25,
                                    fieldLabel: '每页显示数量',
                                    fieldClass :'perpageFieldClass',
                                    id:'perpageFieldId',
                                    selectOnFocus :true,
                                    value:perpage,
                                    listeners:{
                                        change:function(a,b,c){
                                            //ds.load({params:{start:0,limit:b}});
                                            window.location = "./index.php?op=list&tid=<{$smarty.get.tid}>&lg=<{$lg}>&bdid=<{$smarty.get.bdid}>&bdtid=<{$smarty.get.bdtid}>&limit="+b;
                                        }
                                    }
                                }]
                        })
                    ],
                    /*		listeners   : {   
                       render': function(){   
                            oneTbar.render(this.bbar);      //add one tbar   
                        }   
                    },*/
                    bbar: new Ext.PagingToolbar({
                        pageSize: perpage,
                        store: ds,
                        displayInfo: true,
                        displayMsg: '显示第 {0} 条到 {1} 条记录，一共 {2} 条',
                        emptyMsg: "没有记录"
                    }),
                    autoWidth:true,
                    width:Ext.getBody().getWidth(),
                    autoHeight:true,
                    autoShow:true,
                    frame:true,
                    //		autoExpandColumn:true,
                    autoDestroy:true,
                    cls:'',//extra css 
                    loadMask:{msg:"正在加载数据..."},
                    viewConfig: {
                        forceFit:true,
                        scrollOffset:2, // Grid按钮将不会显示上下滚动条
                        layout : function() {      
                            if (!this.mainBody) {      
                                return; // not rendered      
                            }      
                            var g = this.grid;      
                            var c = g.getGridEl();      
                            var csize = c.getSize(true);      
                            var vw = csize.width;      
                            if (!g.hideHeaders && (vw < 20 || csize.height < 20)) { // display:      
                                // none?      
                                return;      
                            }      
                            if (g.autoHeight) {      
                                if (this.innerHd) {      
                                    this.innerHd.style.width = (vw) + 'px';      
                                }      
                            } else {      
                                this.el.setSize(csize.width, csize.height);      
                                var hdHeight = this.mainHd.getHeight();      
                                var vh = csize.height - (hdHeight);      
                                this.scroller.setSize(vw, vh);      
                                if (this.innerHd) {      
                                    this.innerHd.style.width = (vw) + 'px';      
                                }      
                            }      
                            if (this.forceFit) {      
                                if (this.lastViewWidth != vw) {      
                                    this.fitColumns(false, false);      
                                    this.lastViewWidth = vw;      
                                }      
                            } else {      
                                this.autoExpand();      
                                this.syncHeaderScroll();      
                            }      
                            this.onLayout(vw, vh);      
                        }
                    }
                    //		default:{width:50}
                });

                ds.load({params:{start:0,limit:perpage,lg:"<{$lg}>"}});
                grid.render();
                grid.on('columnresize',function(columnIndex,newSize){
                    var column_id=cm.getColumnId(columnIndex);
                    myMask.show();
                    Ext.Ajax.request(
                    {
                        waitMsg:'正在提交....',
                        method:'POST',
                        params:{op:'width_change',id:column_id,width:newSize},
                        url:'<{$thisurl}>',
                        success:function(form, action) {
                            myMask.hide();
                        },
                        failure: function(form, action) {
                        }
                    }
                );
                });
                    <{if ($tree.id|getright:"u")}> grid.on('celldblclick', editHandeler); <{else}>
                    grid.on('celldblclick', function(){Ext.MessageBox.alert('警告','没有编辑权限')});
                    <{/if}>

                    /*ds.on('datachanged',function(){
                Ext.getCmp('dq').setText("当前页C值总量：<font color=red>"+rd.jsonData.dq+"</font>元");
                Ext.getCmp('zong').setText("系统注入C值资源滚动总量：<font color=red>"+rd.jsonData.zong+"</font>元");
                                                                });
                     */
                ds.on('beforeload',function(){
                    Ext.apply(
                    this.baseParams,
                    {
                            <{section name=li loop=$ckbox}>
                            '<{$ckbox[li]}>':'',<{/section}>
                        });
                    //alert(advSearchForm.getForm().getValues(false));
                    if(adstatus!=0){
                        Ext.apply(
                        this.baseParams,
                        advSearchForm.getForm().getValues(false));
	
                    }

                });


                grid.on("rowcontextmenu",function(grid,rowIndex,e){ 
                    e.preventDefault();if(rowIndex<0){return;} 
                    var treeMenu = new Ext.menu.Menu 
                    ([ <{if ($tree.id|getright:"c")}>
                            {xtype:"button",text:"添加",iconCls:"add",pressed:true,handler:function(){
                                addHandeler();
                            }}, <{/if}>
                            {xtype:"button",text:"刷新",iconCls:"i_czxt",pressed:true,handler:function(){
                                window.location.reload();
                            }}<{if ($tree.id|getright:"d")}>, 
                        {xtype:"button",text:"删除",iconCls:"del",pressed:true, handler:function(){
                                delHandeler();	}}<{/if}><{$fstree}> 
                        ]); 
                    treeMenu.showAt(e.getPoint()); 
                }); 


            });
            //-->
            function yuding(id){
                //alert(document.getElementById('num'+id).value);
                Ext.Msg.confirm('提示','你确订要下此订单么？',function(a){
                    if(a=='yes'){
														
                        Ext.Ajax.request({
                            waitMsg:'数据处理中...',
                            url:'./<{$thisurl}>',
                            method:'POST',
                            params:{
                                op:'yuding',
                                id:id,
                                num:document.getElementById('num'+id).value
                            },
                            success:function(response){
                                Ext.MessageBox.alert('恭喜',response.responseText);
                            },
                            failure:function(response){
                                Ext.MessageBox.alert('警告',"无法连接数据库!");
                            }
												
                        });
                    }
                });
            }

        </script>

    </head>

    <body>
        <div id="cms-grid-el">

        </div>
    </body>
</html>